home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / DOS.SWG / 0046_Setting DOS Prompt.pas < prev    next >
Pascal/Delphi Source File  |  1994-02-03  |  3KB  |  83 lines

  1.  
  2. {
  3. TF>How does one alter a DOS environment variable in PASCAL and have the change
  4. TF>reflected after the program terminates, leaving the user in DOS, and the use
  5. TF>types SET?  This has been bugging me for a while. I know that there are two
  6. TF>copies of the environment and I need to access the top one, but I don't know
  7. TF>how.
  8.  
  9. The following example shows how to change the prompt: }
  10.  
  11. function MastEnvSeg(var Envlen: word): word;
  12.   {-returns the master environment segment }
  13.   var
  14.     mcb,temp,handle : word;
  15.     lastmcb : boolean;
  16.   begin
  17.     MastEnvSeg := 0;
  18.     Envlen := 0;
  19.     handle := MemW[0: $ba]; {-$2e * 4 + 2}
  20.     {-The interrupt vector $2e points to the first paragraph of
  21.       allocated to the command processor}
  22.     mcb := pred(handle);
  23.     {-mcb now points to the memory control block for the command processor}
  24.     repeat
  25.       temp := Mcb+MemW[Mcb:3]+1;
  26.       if (Mem[temp:0] = $4d) and (MemW[temp:1] = handle) then begin
  27.         lastmcb := false;
  28.         mcb     := temp;
  29.       end
  30.       else
  31.         lastmcb := true;
  32.     until lastmcb;
  33.     EnvLen := Mem[Mcb:3] shl 4;
  34.     MastEnvSeg := succ(Mcb);
  35.    end;
  36.  
  37.  
  38.   procedure InitNewPrompt;
  39.   {-set up a new prompt for shelling to dos}
  40.   type
  41.     _2karray  = array[1..2048] of byte;
  42.     SegPtr    = ^_2karray;
  43.   const
  44.     NewPrompt : string =
  45.     ('PROMPT=Type EXIT to return to program$_$p$g'+#0);
  46.   var
  47.     EnvSegment,
  48.     NewEnvSeg      : word;
  49.     PtrSeg,
  50.     NewEnv         : SegPtr;
  51.   begin
  52.     EnvSegment := memw[prefixseg:$2C];
  53.     {-this gets the actual starting segment of the current program's env}
  54.  
  55.     PtrSeg := ptr(pred(EnvSegment),0);
  56.     {-The segment of the program's MCB - (Memory control block) }
  57.  
  58.     getmem(NewEnv,1072+length(NewPrompt));
  59.     {-Allocate heap memory and allow enough room for a dummy mcb }
  60.  
  61.     if ofs(NewEnv^) <> 0 then
  62.       NewEnvSeg := seg(NewEnv^) + 2
  63.     else
  64.       NewEnvSeg := succ(seg(NewEnv^));
  65.     {-Force the new environment to start at paragraph boundary}
  66.  
  67.     move(PtrSeg^,mem[pred(NewEnvSeg):0],16);
  68.     {-copy the old mcb and force to paragraph boundary}
  69.  
  70.     memw[pred(NewEnvSeg):3] := (1072+length(NewPrompt)) shr 4;
  71.     {-Alter the environment length by changing the dummy mcb}
  72.  
  73.     move(NewPrompt[1],memw[NewEnvSeg:0],length(NewPrompt));
  74.     {-install new prompt}
  75.  
  76.     memw[prefixseg:$2C] := NewEnvSeg;
  77.     {-let the program know where the new env is}
  78.  
  79.     move(mem[EnvSegment:0],mem[NewEnvSeg:length(NewPrompt)],1024);
  80.     {-shift the old env to the new area}
  81.   end;
  82.  
  83.